package com.cy.myblog.model;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

@Entity
@Table(name="tarticle")
public class Tarticle implements Serializable{

	/**
	 * 文章实体类
	 */
	private static final long serialVersionUID = 3791816316001812943L;
	private String           id;
	private String           title;
	private Tuser            tuser;
	private String           overview;
	private String           content;
	private String           filename;
	private Date             releasetime;
	private int              views;
	private Tclassify        tclassify;
	private int              support;
	private int              state;
	private Set<Tcomment>    comments;
	private Set<Tmultimedia> multimedias;

	public Tarticle() {
		super();
	}

	public Tarticle(String id, String title, Tuser tuser, String overview, String content, String filename, Date releasetime, int views, Tclassify tclassify, int support, int state) {
		this.id = id;
		this.title = title;
		this.tuser = tuser;
		this.overview = overview;
		this.content = content;
		this.filename = filename;
		this.releasetime = releasetime;
		this.views = views;
		this.tclassify = tclassify;
		this.support = support;
		this.state = state;
	}

	@Id
	@Column(name = "id", unique = true, nullable = false, length = 38)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "title",nullable = false, length = 50)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "userid")
	@JSON(serialize=false)
	public Tuser getTuser() {
		return tuser;
	}

	public void setTuser(Tuser tuser) {
		this.tuser = tuser;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "classifyid")
	@JSON(serialize=false)
	public Tclassify getTclassify() {
		return tclassify;
	}

	public void setTclassify(Tclassify tclassify) {
		this.tclassify = tclassify;
	}

	public String getOverview() {
		return overview;
	}

	public void setOverview(String overview) {
		this.overview = overview;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "releasetime")
	public Date getReleasetime() {
		return releasetime;
	}

	public void setReleasetime(Date releasetime) {
		this.releasetime = releasetime;
	}

	public int getViews() {
		return views;
	}

	public void setViews(int views) {
		this.views = views;
	}


	public int getSupport() {
		return support;
	}

	public void setSupport(int support) {
		this.support = support;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}
	
    @OneToMany(mappedBy = "article")
    @LazyCollection(LazyCollectionOption.EXTRA)
	@JSON(serialize=false)
	public Set<Tcomment> getComments() {
		return comments;
	}

	public void setComments(Set<Tcomment> comments) {
		this.comments = comments;
	}

	@OneToMany(mappedBy = "article")
	@LazyCollection(LazyCollectionOption.EXTRA)
	@JSON(serialize=false)
	public Set<Tmultimedia> getMultimedias() {
		return multimedias;
	}

	public void setMultimedias(Set<Tmultimedia> multimedias) {
		this.multimedias = multimedias;
	}

}
